package com.buss.vipUser.controller;


import com.buss.common.entity.HxVipUserEntity;
import com.buss.common.service.SysServiceI;
import com.buss.vipUser.service.VipUserService;
import com.buss.vipUser.trans.form.VipUserForm;
import com.buss.vipUser.trans.vo.VipUserVo;
import org.jweb.core.bean.PageMode;
import org.jweb.core.bean.ReplyDataMode;
import org.jweb.core.query.hibernate.qbc.CriteriaQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/vipUser")
public class VipUserController {
    @Autowired
	private VipUserService vipUserService;

    @Autowired
    private SysServiceI sysService;

    @RequestMapping("/pageList")
    @ResponseBody
    public Object vipList (VipUserForm vipUserForm) {

        ReplyDataMode dataMode = new ReplyDataMode();
        vipUserForm.setIsDelete("0");
        CriteriaQuery cq = vipUserForm.getCriteriaQuery();
        Map< String, Object> orderby = new HashMap<>();
        orderby.put("sort", "desc");
        cq.setOrder(orderby);
        int pageNo = Integer.parseInt(vipUserForm.getPageNo());
        int pageSize = Integer.parseInt(vipUserForm.getPageSize());

        PageMode vipUserModel = sysService.list4page(cq, pageNo, pageSize);
        List<HxVipUserEntity> uas = vipUserModel.getResult();
        List<VipUserVo> vipUserVos = new ArrayList<>();
        VipUserVo vipUserVo = null;
        for(HxVipUserEntity ua : uas) {
            vipUserVo = new VipUserVo();

            vipUserVo.copyEntity(ua);

            vipUserVos.add(vipUserVo);
        }
        vipUserModel.setResult(vipUserVos);
        dataMode.setSuccess(true);
        dataMode.setData(vipUserModel);
        return dataMode;
    }


    @RequestMapping({ "/byIdContent.do" })
    @ResponseBody
    public ReplyDataMode byIdContent(HttpServletRequest request)
            throws ServletException, IOException {
        ReplyDataMode j = new ReplyDataMode();
        List<HxVipUserEntity> entityList = null;

        String id = request.getParameter("id");
        if(id!=null&&id!=""){
            entityList = sysService.findByProperty(HxVipUserEntity.class, "id", id);
        }



        List<VipUserVo> vipUserVos = new ArrayList<>();
        VipUserVo vipUserVo = null;
        for(HxVipUserEntity e : entityList){
            vipUserVo = new VipUserVo();
            vipUserVo.copyEntity(e);

            vipUserVos.add(vipUserVo);
        }

        j.setData(vipUserVos);
        j.setStatusCode("200");
        j.setSuccess(true);

        return j;
    }
}
